package cn.net.msg.web.action.member;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.interceptor.ServletRequestAware;

import cn.net.msg.service.MemberService;
import cn.net.msg.web.formbean.Member;

import com.opensymphony.xwork2.ActionSupport;


public class PasswordAction extends ActionSupport implements ServletRequestAware{
    
    private static final long serialVersionUID = -7574227471454774126L;
    private HttpServletRequest request;
    @Resource(name="memberService")
    MemberService service;
    
    public Member getMember() {  
        return member;  
    }  
  
    public void setMember(Member member) {  
        this.member = member;  
    }  
  
    private Member member = new Member();  
    
    @Override
    public void setServletRequest(HttpServletRequest request) {
        // TODO Auto-generated method stub
        this.request=request;
    }
    
    /**
     * 重置密码界面
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public String resetPasswordUI() {
        return "resetpasswordui";
    }

    /**
     * 重置密码
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public String doResetPassword() {
        if (service.isExsitEmail(member.getEmail())) {
            service.updateUserPassword(member.getEmail(),member.getConfirmpassword());
            return "resetpasswordsuccess";
        } else {
            request.setAttribute("email", member.getEmail());
            request.setAttribute("message", "不存在此账户，请重新输入");
            return "resetpasswordui";
        }
    }


}
